<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/font-awesome.min.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
  </head>
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>{$nav}</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="x-body x-admin">
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('新增规则','add')"><i class="layui-icon"></i>新增</button>
        <span class="x-right" style="line-height:40px">共有数据：{$count}条</span>
      </xblock>
      <div class="layui-table-body layui-table-main" style="width: 100%;">
      <table class="layui-table layui-form">
        <thead>
          <tr>
            <th width="20">
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th width="70">ID</th>
            <th>规则名</th>
            <th>对应方法</th>
            <th style="width: 5%;text-align: center;">图标</th>
            <th style="text-align: center;">菜单状态</th>
            <th style="text-align: center;width: 60px;">排序</th>
            <th style="text-align: center;">操作</th>
          </tr>
        </thead>
        <tbody class="x-cate">
          {volist name="ruleRes" id="rule"}
          <tr cate-id='{$rule.id}' fid='{$rule.pid}'>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$rule.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$rule.id}</td>
            <td>
              {if condition="($rule['level'] == '0') OR ($rule['level'] == '1')"}
                <?php echo str_repeat('&nbsp;&nbsp;',$rule['level']*2);?>
                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                {$rule.title}
              {else/}
                <?php echo str_repeat('&nbsp;&nbsp;',$rule['level']*3);?>
                ├{$rule.title}
              {/if}
              <button class="layui-btn" onclick="x_admin_show('新增规则','add/rule_id/{$rule.id}')" style="float: right;">新增子规则</button>
            </td>
            <td>{$rule.name}</td>
            <td style="text-align: center;">
              <i class="fa {$rule.icon} fa-fw"></i>
            </td>
            <td class="td-status" style="text-align: center;">
                <input type="checkbox" name="menu" lay-skin="switch" lay-text="显示|隐藏" {if condition="$rule['menu'] eq 1"}checked{/if} lay-filter="menu" id="{$rule.id}" value="{$rule.menu}">
            </td>
            <td style="text-align: center;">
              <input type="text"  class="layui-input" style="width: 40px;display: inline;" id="{$rule.id}" onblur="sort(this)" name="sort" value="{$rule.sort}">
            </td>
            <td class="td-manage" style="text-align: center;">
              <a title="编辑" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('编辑规则','edit/id/{$rule.id}')" href="javascript:;">
                <i class="layui-icon">&#xe642;编辑</i>
              </a>
              <a title="删除" class='layui-btn layui-btn-xs layui-btn-danger' style="margin: 0px;" onclick="member_del(this,{$rule.id})" href="javascript:;">
                <i class="layui-icon">&#xe640;删除</i>
              </a>
            </td>
          </tr>
          {/volist}
        </tbody>
      </table>
      </div>
    </div>
    <script>
      layui.use(['form'], function(){
        form = layui.form;
        /*菜单开关*/
        form.on('switch(menu)', function(data){
          var obj=data.elem;
          var id = data.elem.id;
          var menu = data.value;
          $.ajax({
              type:'POST',
              dataType:'json',
              data:{menu:menu,id:id},
              url:"{:url('AuthRule/changeStatus')}",
              success:function(o){
                if(o.icon == 1){
                  $(obj).attr('value',1);
                }else{
                  $(obj).attr('value',0);
                }
                layer.msg(o.msg,{icon: o.icon,time:1000});
              }
            });
        });
      });
      
      /*用户-删除规则*/
      function member_del(obj,id){
          layer.confirm('确认要删除该规则吗？',function(index){
              //发异步删除数据
              $.ajax({
                type:'POST',
                dataType:'json',
                data:{id:id},
                url:"{:url('AuthRule/del')}",
                success:function(o){
                  if(o.icon ==1){
                    $(obj).parents("tr").remove();
                  }
                  layer.msg(o.msg,{icon:o.icon,time:1000});
                }
              });
          });
      }
      /*批量删除规则*/
      function delAll(argument){
        var data = tableCheck.getData();
        if(data == ''){
          layer.msg('请先勾选',{icon:2,time:1000});
          return false;
        }
        layer.confirm('确认要批量删除这些规则吗？',function(index){
            //发异步删除数据
            $.ajax({
              type:'POST',
              dataType:'json',
              data:{data:data},
              url:"{:url('AuthRule/delAll')}",
              success:function(o){
                if(o.icon ==1){
                  $(".layui-form-checked").not('.header').not('.id').parents('tr').remove();
                }
                layer.msg(o.msg,{icon:o.icon,time:1000});
              }
            });
        });
      }
      /*栏目排序*/
      function sort(o){
        var id =$(o).attr('id');
        var sort=$(o).val();
          $.ajax({
            type:'POST',
            dataType:'json',
            data:{id:id,sort:sort},
            url:"{:url('AuthRule/sort')}",
            success:function(o){
              layer.msg(o.msg,{icon:o.icon,time:1000});
            }
          });
      }
    </script>
  </body>

</html>